/**
 * @file usr_ntc.h
 * @author 黑马小乌龟 (532352406@qq.com)
 * @brief 
 * @version 0.1
 * @date 2025-10-18
 * 
 * @copyright Copyright (c) 2025
 * 
 */
#ifndef USR_NTC__H_H
#define USR_NTC__H_H

#ifdef __cplusplus
extern "C"{
#endif
#include<stdint.h>
#include<stdio.h>

#include "hc32_ll.h"
#include "ev_hc32f334_lqfp64_bsp.h"




/* ADC unit instance for this example. */
#define NTC_ADC_UNIT                        (CM_ADC2)
#define NTC_ADC_PERIPH_CLK                  (FCG3_PERIPH_ADC2)

/* ADC sequence to be used. */
#define NTC_ADC_SEQ                         (ADC_SEQ_A)
/* Flag of conversion end. */
#define NTC_ADC_EOC_FLAG                    (ADC_FLAG_EOCA)

/* ADC reference voltage. The voltage of pin VREFH. */
#define NTC_ADC_VREF                        (2.8F)

/* ADC accuracy(according to the resolution of ADC). */
#define NTC_ADC_ACCURACY                    (1UL << 12U)

/* Calculate the voltage(mV). */
#define NTC_ADC_CAL_VOL(adcVal)             (uint16_t)((((float32_t)(adcVal) * NTC_ADC_VREF) / ((float32_t)NTC_ADC_ACCURACY)) * 1000.F)

/* Timeout value. */
#define NTC_ADC_TIMEOUT_VAL                 (1000U)

int ntc_adc_polling(int *p_temperature);

#ifdef __cplusplus
}
#endif

#endif //USR_NTC__H_H


